﻿
@{
    ViewBag.Title = "OperateList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content-header">
    <h1>
        操作日志
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">操作日志</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <div class="bs-example">
                        <ul class="nav nav-tabs">
                            <li role="presentation" class="active"><a href="#">日志信息</a></li>
                            <li role="presentation"><a href="@Url.Action("OperateChart","Log")">日志分析</a></li>
                        </ul>
                    </div>
                    <div class="form-inline" style="margin-top:10px;">
                        <div class="form-group">
                            <label>模块</label>
                            <select name="selMenu" id="selMenu" class="form-control"></select>
                            <select name="selMenuSub" id="selMenuSub" class="form-control"></select>
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="20" id="txtStartDate" autocomplete="off" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="txtEndDate" maxlength="20" id="txtEndDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnImport">导出</button>
                        </div>

                        <h3 class="box-title"></h3>
                    </div>
                </div>

                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover body-table-head">
                        <colgroup>
                            <col style="width:10%" />
                            <col style="width:6%" />
                            <col style="width:8%" />
                            <col style="width:6%" />
                            <col style="width:15%" />
                            <col style="width:15%" />
                            <col style="width:10%" />
                            <col style="width:6%" />
                        </colgroup>
                        <thead>
                            <tr>
                                <th>模块</th>    
                                <th>用户</th>
                                <th>事件</th>
                                <th>来源</th>
                                <th>事件类型</th>
                                <th>返回结果</th>
                                <th>发生时间</th>
                                <th class="t_c">操作</th>
                            </tr>
                        </thead>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each data}}
            {{if $value.CurrentCheckCode!=$value.CheckCode}}
            <tr class="danger">
                {{else}}
            <tr>
                {{/if}}
                <td>{{$value.ModuleName}}</td>
                <td>{{$value.UserName}}</td>
                <td>{{$value.Incident}}</td>
                <td>{{$value.Source}}</td>
                <td>{{$value.IncidentTypeName}}</td>
                <td>{{$value.Result}}</td>
                <td>{{$value.CreatedDate}}</td>
                <td class="t_c">
                    <button type="button" class="btn btn-info btn-xs" onclick="info({{$value.LogId}})">详情</button>
                </td>
            </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            initBindMenu();
            initBindMenuSub();
            search();
            $("#txtStartDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#txtEndDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#btnSearch").click(function () {
                pageIndex = 1;
                search();
            });

            $("#btnImport").click(function () {
                // importData();
                var url = '@Url.Action("ImportLogOperateDataToExcel", "Log")'
                downExcel(url);
            });
        });

        //页码
        var pageIndex = 1;
        //查询
        function search() {
            var startdate = $("#txtStartDate").val();
            var enddate = $("#txtEndDate").val();
            var defaultDate = '@DateTime.Now.ToString("yyyy-MM-dd")';
            var msg = "开始日期不能大于结束日期";
            if (startdate == '') {
                startdate = defaultDate;
            }
            if (enddate == '') {
                enddate = defaultDate;
                msg = "开始日期不能大于当前日期";
            }
            var start = new Date(startdate.replace("-", "/").replace("-", "/"));
            var end = new Date(enddate.replace("-", "/").replace("-", "/"));
            var dfDate = new Date(defaultDate.replace("-", "/").replace("-", "/"));
            if (start > dfDate) {
                BMCW.alert(msg);
                return false;
            }
            if (end < start) {
                BMCW.alert(msg);
                return false;
            }
            var url = '@Url.Action("GetLogOperatePageList", "Log")';
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'GET',
                dataType: "json",
                data: {
                    rows: 10,
                    page: pageIndex,
                    selMenuId: $("#selMenu").val(),
                    selMenuSubId: $("#selMenuSub").val(),
                    txtStartDate: $("#txtStartDate").val(),
                    txtEndDate: $("#txtEndDate").val()
                },
                success: function (o) {
                    if (o.data.length < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        $('#pagination').twbsPagination("destroy");
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var html = template('dataItemTpl', o);
                    document.getElementById('tbodylist').innerHTML = html;
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: o.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            search();
                        }
                    });
                }
            });
        }

        function info(id)
        {
            var url = '@Url.Action("LogOperateInfo", "Log")?logId='+id;
            BMCW.showTopLayer('操作日志详情', url, 550, 600);
        }

        function downExcel(iframeUrl) {
            if (!iframeUrl) {
                return;
            }
            var body = document.getElementsByTagName("body")[0];
            var downloadIframe = document.createElement("iframe");
            downloadIframe.setAttribute("src", iframeUrl);
            downloadIframe.setAttribute("style", "display:none;")
            body.appendChild(downloadIframe);
        }

        //父级菜单
        function initBindMenu() {
            $("#selMenu").append("<option value='0'>全部</option>");
            BMCW.ajax({
                url: '@Url.Action("GetParentMenuList", "Authority")',
                type: "GET",
                success: function (o) {
                    if (o.status == 0) {
                        $.each(o.data, function (i) {
                            $("#selMenu").append("<option value='" + o.data[i].MenuID + "'>" + o.data[i].MenuName + "</option>");
                        });
                    }
                }
            });
        }

        //子类菜单
        function initBindMenuSub() {
            $("#selMenuSub").append("<option value=''>全部</option>");
            $("#selMenu").bind("change", function () {
                var pId = $(this).val();
                BMCW.ajax({
                    url: '@Url.Action("GetMenuListByParentId", "Authority")',
                    data: { "parentId": pId },
                    type: "GET",
                    success: function (rd) {
                        if (rd.status == 0) {
                            $("#selMenuSub").empty();
                            $("#selMenuSub").append("<option value=''>全部</option>");
                            var dataObj = rd.data;
                            for (var i = 0; i < dataObj.length; i++) {
                                $("#selMenuSub").append("<option value='" + dataObj[i].MenuID + "'>" + dataObj[i].MenuName + "</option>");
                            }
                        }
                    }
                })
            });
        }


    </script>
}




